-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Signed integers #1718
Signed integers #1718
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com>
2c7c97c
to
8d89684
Compare
I added the missing signed ints and rebased on 1.3 |
Co-authored-by: Simon Warta <2603011+webmaster128@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very very nice stuff 🙌 Let's add a CHANGELOG entry and merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial review up to int64
(without tests) inclusive.
Looks good. Will review the other int types later. And take a look at the tests.
/// This operation will panic if `rhs` is zero. | ||
#[inline] | ||
fn rem(self, rhs: Self) -> Self { | ||
Self(self.0.rem(rhs.0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Rely on checked_rem
for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to keep it consistent with the unsigned ones (they have the same implementation for rem).
Actually, I think it might be better to change the ones using self.0.checked_*
to use either self.0.*
, a self.checked_*
call or an explicit message using .expect
. That would give more helpful panic messages.
But I think we can do that later.
} | ||
forward_ref_op_assign!(impl ShlAssign, shl_assign for Int64, u32); | ||
|
||
impl Serialize for Int64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps not worth it, but, move all the serialisations to a int_se
module?
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for Int64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, own int_de
module? Not sure about this, just saying.
Self: Add<A, Output = Self>, | ||
{ | ||
fn sum<I: Iterator<Item = A>>(iter: I) -> Self { | ||
iter.fold(Self::zero(), Add::add) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I hope I didn't miss any typos in indexing sizes, but I don't see any. I am wondering if we could just reexport bnum types. However, I see we do error alignment in checked functions, so maybe it is not the best idea.
closes #1710
bnum
cratebnum
)